<?php if ( !defined('BASEPATH')) exit('No direct script access allowed');

class Read_tasks extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');

	}
	public function index(){
	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'),array('zones' => $this->read_tasks_model->getzoning()));
	  $this->load->view('layouts/footer');
	 }

	public function search_charge_list(){
		$zone = $this->input->post('zone');
		$task_name = $this->input->post('task_name');
		$meter_reader = $this->input->post('meter_reader');
	 	$query = $this->read_tasks_model->search_chg_list($zone, $task_name, $meter_reader);
	 	if(!empty($query)) {
			echo json_encode($query);
		}else{
			echo json_encode("none");
		}
	 }

	public function add_form(){
		$this->load->view($this->session->userdata('foradd'),array(
			'zones'	=> $this->read_tasks_model->getzoning(),
			'meter_reader'	=> $this->read_tasks_model->getusers()
		));
	}
	public function edit_form($id){
		$this->load->view($this->session->userdata('foredit'),array(
			'zones'	=> $this->read_tasks_model->getzoning(),
			'reads'	=> $this->read_tasks_model->getreadtasks($id),
			'meter_reader'	=> $this->read_tasks_model->getusers2()
		));
	}
	public function view_form($id){
		$this->load->view($this->session->userdata('forview'),array(
			'zones'	=> $this->read_tasks_model->getzoning(),
			'reads'	=> $this->read_tasks_model->getreadtasks($id),
			'meter_reader' => $this->read_tasks_model->getusers2()
		));
	}


	public function insert(){
		$task_name = $this->input->post('task_name');
		$zone = $this->input->post('zone');
		$meter_reader = $this->input->post('meter_reader');
		$seq_from = $this->input->post('seq_from');
		$seq_to = $this->input->post('seq_to');
		$year = $this->input->post('year');
		$month = $this->input->post('month');
		$user = $this->session->userdata('user_id');
		$data = array($task_name, $zone, $meter_reader, $seq_from, $seq_to, $year, $month, $user);
		echo json_encode($this->read_tasks_model->insert($data));
	}

	public function update(){
		$task_id = $this->input->post('task_id');
		$task_name = $this->input->post('task_name');
		$zone = $this->input->post('zone');
		$meter_reader = $this->input->post('meter_reader');
		$seq_from = $this->input->post('seq_from');
		$seq_to = $this->input->post('seq_to');
		$year = $this->input->post('year');
		$month = $this->input->post('month');
		$user = $this->session->userdata('user_id');
		$data = array($task_id, $task_name, $zone, $meter_reader, $seq_from, $seq_to, $year, $month, $user);
		echo json_encode($this->read_tasks_model->update($data));
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */